package com.woniuxy01;

import java.util.*;

/**
 * @author 作者
 * @create 2025-07-31 11:46
 */
public class Test02 {
    public static void main(String[] args) {
//        ArrayList<Map<String,List<Sutdnet>>>;

        Map<String,Student> class1 = new HashMap<>();
        class1.put("s001", new Student(1,"zs",11));
        class1.put("s002", new Student(2,"ls",12));

        Map<String,Student> class2 = new HashMap<>();
        class2.put("s001", new Student(1,"ww",11));
        class2.put("s002", new Student(2,"zl",12));

        ArrayList<Map<String,Student>> school1 = new ArrayList<>();
        school1.add(class1);
        school1.add(class2);
        System.out.println(school1);
        for(Map<String,Student> classes: school1){
            Set<Map.Entry<String,Student>> students=classes.entrySet();
            System.out.println("遍历每个班的学生");
            for(Map.Entry<String,Student> entryStudent :students){
                System.out.println(entryStudent.getKey());
                System.out.println(entryStudent.getValue());
            }
        }

        Map<String,Map<String,Student>> school2 = new HashMap<>();
        school2.put("c001",class1);
        school2.put("c002",class2);
        System.out.println(school2);

//        Set<Map.Entry<String,Map<String,Student>>> classes = school2.entrySet();
//        for(Map.Entry<String,Map<String,Student>>  myclass : classes){
//            System.out.println(myclass.getKey());
//            Map<String, Student> students = myclass.getValue();
//            Set<Map.Entry<String, Student>> entries = students.entrySet();
//            for( Map.Entry<String, Student>  entry: entries){
//                System.out.println(entry.getKey());
//                System.out.println(entry.getValue());
//            }
//        }

    }

    private static void test09() {
        List<Student> class1 = new ArrayList<>();
        class1.add(new Student(1, "zs", 11));
        class1.add(new Student(2, "ls", 12));
        //一个班：学生集合
        List<Student> class2 = new ArrayList<>();
        class2.add(new Student(1, "ww", 13));
        class2.add(new Student(2, "zl", 12));

        Map<String, List<Student>> school = new HashMap<>();
        school.put("class001", class1);
        school.put("class002", class1);
        System.out.println(school);

        Set<Map.Entry<String, List<Student>>> classes = school.entrySet();
        for (Map.Entry<String, List<Student>> myclass : classes) {
            System.out.println(myclass.getKey());
            List<Student> student = myclass.getValue();
            System.out.println("遍历所有学生");
        }
    }

    private static void test08() {
        //一个班：学生集合
        List<Student> class1 = new ArrayList<>();
        class1.add(new Student(1, "zs", 11));
        class1.add(new Student(2, "ls", 12));
        //一个班：学生集合
        List<Student> class2 = new ArrayList<>();
        class2.add(new Student(1, "ww", 13));
        class2.add(new Student(2, "zl", 12));
        //一个学校:班级集合
        List<List<Student>> school = new ArrayList<>();
        //学校添加班
        school.add(class1);
        school.add(class2);
        System.out.println(school);
        //遍历
        for (List<Student> myClass : school) {
            System.out.println("遍历一个班");
            for (Student student : myClass) {
                System.out.println(student);
            }
        }
    }

    private static void test07() {
        Map<User, String> map = new HashMap<>();
        map.put(new User(1, "zs", 11), "1");
        map.put(new User(2, "ls", 12), "2");
        map.put(new User(1, "zs", 11), "1");
    }

    private static void test06() {
        Map<Integer, String> map = new HashMap<Integer, String>();
        map.put(1, "aaa");
        map.put(2, "bbb");
        map.put(3, "ccc");
        map.put(4, "aaa");
        //Map遍历,keySet();获取所有键的集合
        Set<Integer> keys = map.keySet();
        for (Integer key : keys) {
            System.out.println(key);
            System.out.println(map.get(key));
        }
        System.out.println("--------------");
        //Map遍历,values();获取所有值的集合
        Collection<String> values = map.values();
        for (String value : values) {
            System.out.println(value);
        }
        System.out.println("--------------");
        //Map遍历.entrySet():获取键值对的集合
        //Entry,是Map接口中定义的一个内部接口，代表key-value的类型
        Set<Map.Entry<Integer, String>> entries = map.entrySet();
        for (Map.Entry<Integer, String> entry : entries) {
            System.out.println(entry.getKey());
            System.out.println(entry.getValue());
        }
    }

    private static void test05() {
        Map<String, Integer> map = new HashMap();
        map.put("aaa", 1);
        map.put("bbb", 2);
        map.put("ccc", 3);
        Set<String> keys = map.keySet();
        for (String key : keys) {
            System.out.println(key + ":" + map.get(key));
        }
    }


    private static void test04() {
        Map<Integer, String> map = new HashMap<Integer, String>();
        map.put(1, "aaa");
        map.put(2, "bbb");
        System.out.println(map);
        System.out.println(map.containsKey(1));
        System.out.println(map.containsKey(3));
        System.out.println(map.containsValue("aaa"));
        System.out.println(map.containsValue("aa"));
    }

    private static void test03() {
        Map<String, Student> map = new HashMap<>();
        map.put("001", new Student(1, "zs", 11));
        map.put("002", new Student(2, "ls", 11));
        System.out.println(map);
        Student student1 = map.get("001");
        Student student2 = map.get("002");
        System.out.println(student1);
        System.out.println(student2);
    }

    private static void test01() {
        //创建map对象，指定key的类型和value的类型
        Map<Integer, String> map = new HashMap<Integer, String>();
        //添加元素:指定key-value
        map.put(1, "zs");
        map.put(2, "ls");
        //map通过key访问value
        System.out.println(map.get(1));
        System.out.println(map.get(2));
        System.out.println(map.get(3));
        System.out.println(map);
    }
}
